package com.spzx.test1.t3;
/*
    并非全力
*/

import ch.qos.logback.core.testUtil.RandomUtil;
import org.apache.commons.lang3.RandomUtils;

import java.util.RandomAccess;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class test1 {
    public static void main(String[] args) throws InterruptedException, ExecutionException {


        FutureTask<Integer> task1 = new FutureTask<Integer>(() -> {
            System.out.println(Thread.currentThread().getName() + "运算人工成本");
            try {
                TimeUnit.SECONDS.sleep(RandomUtils.nextInt(1, 5));
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "人工运行结束");
            return 100;
        });
        new Thread(task1).start();


        FutureTask<Integer> task2 = new FutureTask<Integer>(() -> {
            System.out.println(Thread.currentThread().getName() + "运算材料成本");
            try {
                TimeUnit.SECONDS.sleep(RandomUtils.nextInt(1, 5));
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "材料运行结束");
            return 100;
        });
        new Thread(task2).start();

        FutureTask<Integer> task3 = new FutureTask<Integer>(() -> {
            System.out.println(Thread.currentThread().getName() + "运算工程基础造价成本");
            try {
                TimeUnit.SECONDS.sleep(RandomUtils.nextInt(1, 5));
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "工程基础造价运行结束");
            return 100;
        });
        new Thread(task3).start();

        Integer integer1 = task1.get();
        Integer integer2 = task2.get();
        Integer integer3 = task3.get();
        int result = integer1+integer2+integer3;
        System.out.println("总工程报价"+result );


    }
}
